import java.io.*;

// Imdb encoding: ISO-8859-1
class CachedBinaryWriter
{
  CachedBinaryWriter(String filePath)
  {
    ready = false;
    try {
      FileOutputStream file = new FileOutputStream(filePath);
      BufferedOutputStream bout = new BufferedOutputStream(file, BUFFER_SIZE);
      DataOutputStream dos = new DataOutputStream(bout);
      output = dos;     
      ready = true;
    } catch (Exception e)
    {
      println("ERROR in opening file: " + e.getMessage());
    }
  }
  
  boolean isReady()
  {
    return ready;
  }
  
  void writeInt(int i)
  {
    try {
      output.writeInt(i);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  
  void closeFile()
  {
    try {
      output.close();
    } catch (Exception e) {
      println("ERROR in closeFile: " + e.getMessage());
    }
  }
  
  void flushFile()
  {
    try {
      output.flush();
    } catch (Exception e) {
      println("ERROR in closeFile: " + e.getMessage());
    }
  }
  
  
  private boolean ready;
  private DataOutputStream output;
}
